<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>钢链网-商城</title>
	<link rel="stylesheet" href="/resource/css/gl_index.css">
	<link rel="stylesheet" href="/resource/css/gl_shopping.css">
    <link rel="stylesheet" href="/resource/css/gl_showBo.css">
    <script src="/resource/js/gl_showBo.js"></script>
	<script src="/resource/js/jquery-1.11.3.min.js"></script>
	<script src="/resource/js/gl_index.js"></script>
    <script src="/resource/js/jquery.fly.min.js"></script>
    <!--[if lte IE 9]>
    <script src="/resource/js/requestAnimationFrame.js"></script>
    <![endif]-->
	<script>
			// 点击找货 登录
			function login(){
				$('.popup').show();
				$('.popup-login').show();
			};
        $(function(){
            //购物车动画
            $(document).delegate(".addcar","click",function(event){
                var offset = $("#shopping").offset();
                var img = './resource/img/logo_shop_tra.png';
                var flyer = $('<img class="u-flyer" src="'+img+'">');
                var product_id = $(this).attr('product_id');
                flyer.fly({
                    start: {
                        left: event.pageX,
                        top: event.pageY-$(document).scrollTop()
                    },
                    end: {
                        left: offset.left+10,
                        top: offset.top-$(document).scrollTop()+100,
                        width: 0,
                        height: 0
                    },
                    onEnd: function(){
                        $.ajax({
                            url: "/shop_add_cart",
                            type: "get",
                            data: "product_id="+product_id,
                            success: function (msg) {
                                $("#cart_info").html(msg);
                                if($('#cart_num span').length<1){
                                    $('#cart_num').append('<span>1</span>');
                                }else{
                                    $('#cart_num span').html(parseInt($('#cart_num span').html())+1);
                                }
                                if($('#cart_num_top span').length<1){
                                    $('#cart_num_top').append('<span>1</span>');
                                }else{
                                    $('#cart_num_top span').html(parseInt($('#cart_num_top span').html())+1);
                                }
                            }
                        });
                        this.destory();
                    }
                });
            });
			//搜索AJAX
			$.ajax({
				url:'/ajax_shopping',
				type:'post',
				data:'',
				success:function(data){
					$.each(data,function(index,arr){
						var str = "";
						$.each(arr,function(i,a){
							if(index == 'address'){
								str += "<li rel="+ a.city_name+">"+a.city_name+"</li>";
								$('[name="address"]').parents('.form-group').find('ul').html(str);
							}
							if(index == 'brand'){
								str += "<li rel="+ a.brand_id+">"+a.brand_name+"</li>";
								$('[name="brand"]').parents('.form-group').find('ul').html(str);
							}
							if(index == 'storage'){
								str += "<li rel="+ a.storage_id+">"+a.storage_name+"</li>";
								$('[name="storage"]').parents('.form-group').find('ul').html(str);
							}
							if(index == 'factory'){
								str += "<li rel="+ a.factory_id+">"+a.factory_name+"</li>";
								$('[name="factory"]').parents('.form-group').find('ul').html(str);
							}
							if(index == 'material'){
								str += "<li rel="+ a.m_id+">"+a.m_name+"</li>";
								$('[name="material"]').parents('.form-group').find('ul').html(str);
							}
						});
					});
				}
			});

			$('.category').click(function(e){
				var category = $(this);
				e?e.stopPropagation():event.cancelBubble = true;
				if(category.hasClass('open')){
					category.removeClass('open').siblings('.category-cont').hide();
				}else{
					$('.category-cont').hide();
					$('.category').removeClass('open');
					category.addClass('open').siblings('.category-cont').show();
				}
			});

			$('.category-cont').delegate('li','click',function(){
				var name = $(this).html();
				var i_d = $(this).attr('rel');
				$(this).parents('.form-group').find('.category-title').html(name);
				$(this).parents('.form-group').find('input').val(i_d);
				$('.category-cont').hide();
				$('.category').removeClass('open');
			});

			$('.category-cont').click(function(e){
				e?e.stopPropagation():event.cancelBubble = true;
			});

			$(document).click(function(){
				$('.category-cont').hide();
				$('.category').removeClass('open');
			});

        });

	</script>
</head>
<body>
@include('common.shop_head')
<div class="shop-cont main">
	{{--<form action="/shopping" method="post" class="form-inline">--}}
		{{--<div class="form-group">--}}
			{{--<select name="address" id="" class="form-control">--}}
				{{--@foreach($address as $key =>$address1)--}}
					{{--<option value="{{$address1->city_name}}">{{$address1->city_name}}</option>--}}
				{{--@endforeach--}}
			{{--</select>--}}
		{{--</div>--}}
		{{--<div class="form-group">--}}
			{{--<label for="">品名</label>--}}
			{{--<select name="brand" id="" class="form-control">--}}
				{{--<option value="all"></option>--}}
				{{--@foreach($brand as $key =>$brand1)--}}
				{{--<option value="{{$brand1->brand_id}}">{{$brand1->brand_name}}</option>--}}
				{{--@endforeach--}}
			{{--</select>--}}
		{{--</div>--}}
		{{--<div class="form-group">--}}
			{{--<label for="">材质</label>--}}
			{{--<select name="material" id="" class="form-control">--}}
				{{--<option value="all"></option>--}}
				{{--@foreach($material as $key =>$material1)--}}
					{{--<option value="{{$material1->m_id}}">{{$material1->m_name}}</option>--}}
				{{--@endforeach--}}
			{{--</select>--}}
		{{--</div>--}}
		{{--<div class="form-group">--}}
			{{--<label for="">规格</label>--}}
			{{--<input type="text" class="form-control" name="spec">--}}
		{{--</div>--}}
		{{--<div class="form-group">--}}
			{{--<label for="">仓库</label>--}}
			{{--<select name="storage" id="" class="form-control">--}}
				{{--<option value="all"></option>--}}
				{{--@foreach($storage as $key =>$storage1)--}}
					{{--<option value="{{$storage1->storage_id}}">{{$storage1->storage_name}}</option>--}}
				{{--@endforeach--}}
			{{--</select>--}}
		{{--</div>--}}

		{{--<div class="form-group">--}}
			{{--<label for="">钢厂</label>--}}
			{{--<select name="factory" id="" class="form-control">--}}
				{{--<option value="all"></option>--}}
				{{--@foreach($factory as $key =>$factory1)--}}
					{{--<option value="{{$factory1->factory_id}}">{{$factory1->factory_name}}</option>--}}
				{{--@endforeach--}}
			{{--</select>--}}
		{{--</div>--}}
		{{--<div class="form-group">--}}
			{{--<input type="submit" class="form-control btn-search" value="搜索">--}}
		{{--</div>--}}
	{{--</form>--}}
	<form action="/shopping" method="post" class="form-inline">
		<div class="form-group">
			<div class="form-control category">
				<div class="category-title">
					全部
				</div>
				<i></i>
				<input type="hidden" name="address" value="">
			</div>
			<div class="category-cont"><ul></ul></div>
		</div>
		<div class="form-group">
			<label for="">品名</label>
			<div class="form-control category">
				<div class="category-title">
					全部
				</div>
				<i></i>
				<input type="hidden" name="brand" value="">
			</div>
			<div class="category-cont"><ul></ul></div>
		</div>
		<div class="form-group">
			<label for="">材质</label>
			<div class="form-control category">
				<div class="category-title">
					全部
				</div>
				<i></i>
				<input type="hidden" name="material" value="">
			</div>
			<div class="category-cont"><ul></ul></div>
		</div>
		<div class="form-group">
			<label for="">规格</label>
			<input type="text" class="form-control" name="spec">
		</div>
		<div class="form-group">
			<label for="">仓库</label>
			<div class="form-control category">
				<div class="category-title">
					全部
				</div>
				<i></i>
				<input type="hidden" name="storage" value="">
			</div>
			<div class="category-cont"><ul></ul></div>
		</div>
		<div class="form-group">
			<label for="">钢厂</label>
			<div class="form-control category">
				<div class="category-title">
					全部
				</div>
				<i></i>
				<input type="hidden" name="factory" value="">
			</div>
			<div class="category-cont"><ul></ul></div>
		</div>
		<div class="form-group">
			<input type="submit" class="form-control btn-search" value="搜索">
		</div>
		<div class="clear"></div>
	</form>
	@if(!empty($res))
	<table class="table">
		<thead>
			<tr>
				<th width="180px">品名</th>
				<th width="110px">钢厂</th>
				<th width="120px">材质</th>
				<th width="100px">规格</th>
				<th width="150px">仓库</th>
				<th width="95px">件数</th>
				<th width="95px">件重(吨)</th>
				<th width="100px">可供</th>
				<th width="100px">单价(元/吨)</th>
				<th class="last">操作</th>
			</tr>
		</thead>

		<tbody>
		@foreach($data as $key =>$data1)

			<tr>
				<td><div class="name">{{$data1->brand_name}}</div></td>
				<td><div>{{$data1->factory_name}}</div></td>
				<td><div>{{$data1->m_name}}</div></td>
				<td><div>{{$data1->product_spec}}</div></td>
				<td><div>{{$data1->storage_name}}</div></td>
				<td><div>{{$data1->useable_stock}}</div></td>
				<td><div>{{round($data1->piece_weight,2)}}</div></td>
				<td><div>{{round($data1->useable_stock * $data1->piece_weight,2)}}</div></td>
				<td><div ><span>{{$data1->product_price}}</span></div></td>
				<td>
					@if(session_get(UserEnum::USER_INFO_USER_ID))
						<a href="javascript:;"  class="addcar" product_id="{{$data1->product_id}}">购买</a>
					@else
						<a href="javascript:;" onclick='login()'>购买</a>
					@endif
				</td>
			</tr>

		@endforeach
		</tbody>

	</table>
	@else
		<div class="shopping-no">
			<img src="/resource/img/shopping_no.png" alt="">暂时没有找到匹配商品
		</div>
	@endif

	{{$data->links()}}
	{{--<ul class="pagination">--}}
		{{--<li><button disabled="disabled">首页</button></li>--}}
		{{--<li><button disabled="disabled">&#60;上一页</button></li>--}}
		{{--<li class="active"><a href="javascript:;">1</a></li>--}}
		{{--<li><a href="javascript:;">2</a></li>--}}
		{{--<li><a href="javascript:;">3</a></li>--}}
		{{--<li>…</li>--}}
		{{--<li><a href="javascript:;">下一页&#62;</a></li>--}}
		{{--<li><a href="javascript:;">尾页</a></li>--}}
		{{--<li class="last">--}}
			{{--跳转至<input type="text">页<a href="javascript:;">GO</a>--}}
		{{--</li>--}}
	{{--</ul>--}}
</div>
@include('common.shop_foot')
</body>
</html>